function allwords(f)
  for line in io.lines() do
    for word in string.gmatch(line, "%w+") do
      f(word)  -- call the function
    end
  end
end

local count = 0
for w in allwords() do
  if w == "hello" then count = count + 1 end 
end

print(count)